%% Replication code for Emigration and Political Contestation, by Margaret E. Peters and Michael K. Miller
%% Prepared September 13, 2021


% Tables and Figures in Main Paper


% Civil War IV Models (Table 1)

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global se "r"
global dviv "fcow_intwar"
global dv "cow_intwar"

eststo clear
global cond "oecd==0"
eststo: quietly probit $dviv share_wbstocksout loggdp2 d_region2-d_region8 d_year160-d_year211 if $cond, $se
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo: quietly ivprobit $dviv loggdp2 d_region2-d_region8 d_year160-d_year211 ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivprobit $dviv loggdp2 d_region2-d_region8 d_year160-d_year211 ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivprobit $dviv loggdp2 d_region1-d_region7 d_year160-d_year211 ($endog = $em) if $cond, $se
global cond "oecd==0"
eststo: quietly probit $dviv share_wbstocksout rx_$dv $main if $cond, $se
eststo: quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond, $se
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global cond "oecd==0 & bmr == 1"
eststo: quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, drop(d_*) b(3)



% Civil War Predictions (Figure 2)

global se "r"
global dviv "fcow_intwar"
global dv "cow_intwar"
global em "ptot_shareout"
global endog "share_wbstocksout"

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global cond "oecd==0 & bmr == 0"
quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr)
marginsplot, recast(line) recastci(rarea) yline(0)

global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global cond "oecd==0 & bmr == 1"
quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr)
marginsplot, recast(line) recastci(rarea) yline(0)



% Other Contestation Outcomes (Table 2)

global dviv "fucdp_civwarb"
global dv "ucdp_civwarb"
global method "probit"
global ivmethod "ivprobit"

global dviv "fucdp_civscale"
global dv "ucdp_civscale"
global method "oprobit"
global ivmethod "ivreg2"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global method "oprobit"
global ivmethod "ivreg2"

global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
global method "probit"
global ivmethod "ivprobit"

global dviv "fantigovtviol"
global dv "antigovtviol"
global method "nbreg"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global method "oprobit"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global method "probit"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global method "nbreg"
global ivmethod "ivreg2"

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global se "r"
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo clear
global cond "oecd==0"
eststo: quietly $method $dviv share_wbstocksout rx_$dv $main if $cond, $se
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)



% Violent/Non-Violent Event Predictions (Figure 3)

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global se "r"
global method "probit"
global ivmethod "ivprobit"
global em "ptot_shareout"
global endog "share_wbstocksout"

global cond "oecd==0 & bmr == 0"
global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr) saving(file1, replace)
global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr) saving(file2, replace)
combomarginsplot file1 file2, recast(line) recastci(rarea) yline(0)

global cond "oecd==0 & bmr == 1"
global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr) saving(file1, replace)
global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
margins, at(share_wbstocksout=(0(.005).1)) vsquish pred(pr) saving(file2, replace)
combomarginsplot file1 file2, recast(line) recastci(rarea) yline(0)



% Robustness Checks for Emigration Share (Table 3)

global se "r"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

% Varying Controls
global em "ptot_shareout"
global endog "share_wbstocksout"
global main "d_region1-d_region7 fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global main "fdi d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global main "aidfrac d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global main "aidfrac fdi d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global main "vdem_liberal d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

% Lagged 10 & 20 Years
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "l10_ptot_shareout"
global endog "l10_share_wbstocksout"

global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "l20_ptot_shareout"
global endog "l20_share_wbstocksout"

eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, drop(d_*) b(3)

% OECD Included
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo clear
global cond "bmr >= 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

% No imputed values
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond & mod(year,10)==0, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond & mod(year,10)==0, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond & mod(year,10)==0, $se
esttab, keep(share_wbstocksout) b(3)




% Democratic Emigration (Table 4)

global se "r"
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fucdp_civwarb"
global dv "ucdp_civwarb"
global ivmethod "ivprobit"

global dviv "fucdp_civscale"
global dv "ucdp_civscale"
global ivmethod "ivreg2"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
global ivmethod "ivprobit"

global dviv "fantigovtviol"
global dv "antigovtviol"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global ivmethod "ivreg2"


eststo clear
global em "pnetbmr_shareout"
global endog "netbmr_shareout"
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "pmeanbmr_shareout ptot_shareout"
global endog "meanbmr_wbstocksout share_wbstocksout"
global cond "oecd==0"
eststo: quietly ivreg2 $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivreg2 $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivreg2 $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout meanbmr_wbstocksout) b(3)







% Tables and Figures in Online Appendix


% Dyadic Test (Table A1) (uses dyadic migration dataset)

global main "lpop_1 lpop_2 lgdpcap_1 lgdpcap_2 ldist2 dd_contig1-dd_contig5 d_colony2 langshare year ldist2_gdp_2 ldist2_lpop_2 dcontig_gdp_2 dcontig_lpop_2"
global flow "wbshare_full100"
reg $flow $main if polity2_1 < 11, r cluster(dyadid)


% Alternative IV Dyadic Predictions (Figures A1-A2)

global se "r"
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global cond "oecd==0"
global endog "share_wbstocksout"
eststo clear
global em "ptot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px2tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px3tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px4tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px5tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px6tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px7tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px8tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px9tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px10tot_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

global se "r"
global main "d_region1-d_region7 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global ivmethod "ivreg2"

global cond "oecd==0 & bmr==0"
global endog "netbmr_shareout"
eststo clear
global em "pnetbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px2netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px3netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px4netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px5netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px6netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px7netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px8netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px9netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "px10netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout) b(3)


set obs 10
gen ivalt = _n
gen coef = .
gen tstat = .
% Inputted values from tests
gen upp = coef + 1.96*coef/tstat
gen down = coef - 1.96*coef/tstat
replace upp = coef + 1.96*coef/tstat
replace down = coef - 1.96*coef/tstat
set scheme s1color
tw rspike upp down ivalt || sc coef ivalt



% Alternative IV Models for Emigration Share (Table A2)

% FE in Prediction

global se "r"
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global em "pferectot_shareout"
global endog "share_wbstocksout"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, drop(d_*) b(3)
global em "pfetot_shareout"
global endog "share_wbstocksout"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

% Adding Country Mean 

global se "r"
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "pfetot_shareout"
global endog "share_wbstocksout"
global dv "cow_intwar"
global dviv "fcow_intwar"

eststo clear
global cond "oecd==0"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

global dviv "fnavco_violentsize"
global dviv "fnavco_nonviolentsize"

eststo clear
global cond "oecd==0"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

% Bootstrapping (uses dyadic migration dataset)
% Generate 500 dyadic samples using bsample, calculate predicted dyadic emigration, run tests, and store new coefficients as coef using regsave

by var2 oecd, sort: egen sd = sd(coef)
gen tval2 = truecoef2/sd



% Alternative IV Models for Democratic Emigration (Table A3)

% FE in Prediction

global se "r"
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "pfenetbmr_shareout"
global endog "netbmr_shareout"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fucdp_civwarb"
global dv "ucdp_civwarb"
global ivmethod "ivprobit"

global dviv "fucdp_civscale"
global dv "ucdp_civscale"
global ivmethod "ivreg2"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
global ivmethod "ivprobit"

global dviv "fantigovtviol"
global dv "antigovtviol"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global ivmethod "ivreg2"

eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout) b(3)

% Adding Country Mean 

global se "r"
global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global em "pfenetbmr_shareout"
global endog "netbmr_shareout"
global dv "cow_intwar"
global dviv "fcow_intwar"

global dviv "fucdp_civwarb"
global dviv "fantigovtvioldummy"
global dviv "fantigovtpeacedummy"

eststo clear
global cond "oecd==0"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivprobit $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout) b(3)

global dviv "fucdp_civscale"
global dviv "fnavco_violentsize"
global dviv "fantigovtviol"
global dviv "fnavco_nonviolentsize"
global dviv "fantigovtpeace"
eststo clear
global cond "oecd==0"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly ivreg2 $dviv cx_$dv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout) b(3)



% Robustness to Country Outliers (Figure A3)

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global se "r"
global em "ptot_shareout"
global endog "share_wbstocksout"
local counter "1"
set more off
forvalues omit = 2/1000 {
count if ccode==`omit' & year >= 1960 & share_wbstocksout!=.
local test = r(N)
if `test' > 0 {

global cond "oecd==0"
quietly ivprobit $dviv rx_$dv $main ($endog = $em) if $cond & ccode!=`omit', $se

if `counter'==1{
regsave share_wbstocksout using outlier_cw, tstat pval ci autoid 
}
if `counter'>1{
regsave share_wbstocksout using outlier_cw, tstat pval ci autoid append
}

local counter "2"
}
}

encode var, gen(var2)
tab var2, gen(varnum)
hist tstat if varnum1==1



% Placebo Tests for Emigration Share (Table A4)

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year161-d_year206"
global se "r"
global em "ptot_shareout"
global endog "share_wbstocksout"

global dviv "firreg"
global dv "irreg"
global ivmethod "ivprobit"

global dviv "ftp_coups"
global dv "tp_coups"
global ivmethod "ivreg2"

global dviv "fpurges"
global dv "purges"
global ivmethod "ivreg2"

eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr==1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)



% Autocratic Regime Types (Table A5)

global se "r"
global main "d_region1-d_region7 fuelvalue_cap1000 tradefrac pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

eststo clear
global cond "oecd==0 & bmr == 0"
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo: quietly $ivmethod $dviv geddesmil geddesparty rx_$dv $main ($endog = $em) if $cond, $se
global em "pnetbmr_shareout"
global endog "netbmr_shareout"
eststo: quietly $ivmethod $dviv geddesmil geddesparty rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout netbmr_shareout) b(3)

global cond2 "& geddesparty==1"
global cond2 "& geddesparty==0"
global cond2 "& (d_geddes3==1 | d_geddes6==1)"
global cond2 "& !(d_geddes3==1 | d_geddes6==1)"
global cond2 "& ea==1"
global cond2 "& ea==0"
eststo clear
global cond "oecd==0 & bmr == 0"
global em "ptot_shareout"
global endog "share_wbstocksout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
global em "pnetbmr_shareout"
global endog "netbmr_shareout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
esttab, keep(share_wbstocksout netbmr_shareout) b(3)



% Variation by Economic Context (Table A6)

global se "r"
global main "d_region1-d_region7 fuelvalue_cap1000 tradefrac pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global cond "oecd==0"
global em "ptot_shareout"
global endog "share_wbstocksout"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fucdp_civwarb"
global dv "ucdp_civwarb"
global ivmethod "ivprobit"

global dviv "fucdp_civscale"
global dv "ucdp_civscale"
global ivmethod "ivreg2"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
global ivmethod "ivprobit"

global dviv "fantigovtviol"
global dv "antigovtviol"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global ivmethod "ivreg2"

eststo clear
global cond2 " & growth2_alt <= 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
global cond2 " & growth2_alt <= 3.5 & growth2_alt > 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
global cond2 " & growth2_alt > 3.5 & growth2_alt != ."
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
global cond2 " & econcrisis_em==1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
global cond2 " & econcrisis_em==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond $cond2, $se
esttab, keep(share_wbstocksout) b(3)



% Other Receiver Characteristics (Table A7)

global se "r"
global main "d_region1-d_region7 fuelvalue_cap1000 tradefrac pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global cond "oecd==0"

global dviv "fcow_intwar"
global dv "cow_intwar"
global ivmethod "ivprobit"

global dviv "fucdp_civwarb"
global dv "ucdp_civwarb"
global ivmethod "ivprobit"

global dviv "fucdp_civscale"
global dv "ucdp_civscale"
global ivmethod "ivreg2"

global dviv "fnavco_violentsize"
global dv "navco_violentsize"
global ivmethod "ivreg2"

global dviv "fantigovtvioldummy"
global dv "antigovtvioldummy"
global ivmethod "ivprobit"

global dviv "fantigovtviol"
global dv "antigovtviol"
global ivmethod "ivreg2"

global dviv "fnavco_nonviolentsize"
global dv "navco_nonviolentsize"
global ivmethod "ivreg2"

global dviv "fantigovtpeacedummy"
global dv "antigovtpeacedummy"
global ivmethod "ivprobit"

global dviv "fantigovtpeace"
global dv "antigovtpeace"
global ivmethod "ivreg2"

eststo clear
global em "pmeanlgdp_shareout"
global endog "meanlgdp_wbstocksout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global em "pmeanassn_shareout"
global endog "meanassn_wbstocksout"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(meanlgdp_wbstocksout meanassn_wbstocksout) b(3)



% Alternative Dependent Variables (Table A8)

global main "d_region2-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211"
global se "r"
global ivmethod "ivreg2"

global em "ptot_shareout"
global endog "share_wbstocksout"
global dviv "fvdem_csoanti"
global dv "vdem_csoanti"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(share_wbstocksout) b(3)

global em "pnetbmr_shareout"
global endog "netbmr_shareout"
global dviv "fvdem_csoantidem"
global dv "vdem_csoantidem"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(netbmr_shareout) b(3)

global em "pmeanbmr_shareout"
global endog "meanbmr_wbstocksout"
global dviv "fvdem_csoantidem"
global dv "vdem_csoantidem"
eststo clear
global cond "oecd==0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 0"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
global cond "oecd==0 & bmr == 1"
eststo: quietly $ivmethod $dviv rx_$dv $main ($endog = $em) if $cond, $se
esttab, keep(meanbmr_wbstocksout) b(3)



keep if year >= 1960 & year <= 2010

keep country_y ccode region year d_region1-d_region8 tradefrac fuelvalue_cap1000 pop_million area_million ELF loggdp2 growth2_alt regionpolity polity2 polity2_sq d_year160-d_year211 fcow_intwar cow_intwar fantigovtpeace antigovtpeace fantigovtpeacedummy antigovtpeacedummy fnavco_nonviolentsize navco_nonviolentsize fantigovtviol antigovtviol fantigovtvioldummy antigovtvioldummy fnavco_violentsize navco_violentsize fucdp_civscale ucdp_civscale oecd ptot_shareout share_wbstocksout bmr fucdp_civwarb ucdp_civwarb rx_cow_intwar rx_antigovtpeace rx_antigovtpeacedummy rx_ucdp_civwarb rx_ucdp_civscale rx_navco_violentsize rx_antigovtvioldummy rx_antigovtviol rx_navco_nonviolentsize aidfrac fdi vdem_liberal l10_ptot_shareout l10_share_wbstocksout l20_ptot_shareout l20_share_wbstocksout pnetbmr_shareout netbmr_shareout pmeanbmr_shareout meanbmr_wbstocksout px* cx_* pferectot_shareout pfetot_shareout pfenetbmr_shareout firreg irreg ftp_coups tp_coups fpurges purges geddesmil geddesparty d_geddes3 d_geddes6 ea econcrisis_em pmeanlgdp_shareout meanlgdp_wbstocksout pmeanassn_shareout meanassn_wbstocksout fvdem_csoanti vdem_csoanti fvdem_csoantidem vdem_csoantidem



